﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.SqlServer.Dts.Runtime;

namespace ToddMcDermid.SSIS
{
    public partial class FilePropertiesTaskEditor : Form
    {
        #region Private Variables
        private TaskHost _taskHost;
        private Connections _connections;
        #endregion

        #region Constructor
        public FilePropertiesTaskEditor(TaskHost taskHost, Connections connections)
        {
            InitializeComponent();

            this._taskHost = taskHost;
            this._connections = connections;
        }
        #endregion

        #region Form Event Handlers
        private void EmptyTaskWithUIEditor_Load(object sender, EventArgs e)
        {
            try
            {
                this.Text = "File Properties Task - " + this._taskHost.Name;

                #region FilePathNameSource --> cboFilePathNameSource
                this.cboFilePathNameSource.Items.Clear();
                foreach (string propertySourceType in Enum.GetNames(typeof(FilePropertiesTask.PropertySourceType)))
                {
                    this.cboFilePathNameSource.Items.Add(propertySourceType.Replace('_', ' '));
                }

                FilePropertiesTask.PropertySourceType fileNameSource = FilePropertiesTask.PropertySourceType.Static_Value;
                DtsProperty propertyFileNameSource = this._taskHost.Properties["FilePathNameSource"];
                if (propertyFileNameSource != null)
                {
                    fileNameSource = (FilePropertiesTask.PropertySourceType)propertyFileNameSource.GetValue(this._taskHost);
                }

                this.cboFilePathNameSource.SelectedItem = Enum.GetName(typeof(FilePropertiesTask.PropertySourceType), fileNameSource).Replace('_', ' ');
                #endregion

                #region FilePathName --> cboFilePathNameVariable or txtFilePathNameStatic
                this.cboFilePathNameVariable.Items.Clear();
                foreach (Variable variable in this._taskHost.Variables)
                {
                    if ((variable.DataType == TypeCode.String) && (!variable.SystemVariable))
                    {
                        this.cboFilePathNameVariable.Items.Add(variable.QualifiedName);
                    }
                }

                string fileName = "";
                DtsProperty propertyFileName = this._taskHost.Properties["FilePathName"];
                if (propertyFileName != null)
                {
                    fileName = (string)propertyFileName.GetValue(this._taskHost);
                }

                if (fileNameSource == FilePropertiesTask.PropertySourceType.Variable)
                {
                    this.cboFilePathNameVariable.SelectedItem = fileName;
                }
                else
                {
                    this.txtFilePathNameStatic.Text = fileName;
                }
                #endregion

                #region FileMissingAction --> cboFileMissingAction
                this.cboFileMissingAction.Items.Clear();
                foreach (string fileMissingActionType in Enum.GetNames(typeof(FilePropertiesTask.FileMissingActionType)))
                {
                    this.cboFileMissingAction.Items.Add(fileMissingActionType.Replace('_', ' '));
                }

                FilePropertiesTask.FileMissingActionType fileMissingAction = FilePropertiesTask.FileMissingActionType.Task_Fails_if_the_File_Does_Not_Exist;
                DtsProperty propertyFileMissingAction = this._taskHost.Properties["FileMissingAction"];
                if (propertyFileMissingAction != null)
                {
                    fileMissingAction = (FilePropertiesTask.FileMissingActionType)propertyFileMissingAction.GetValue(this._taskHost);
                }

                this.cboFileMissingAction.SelectedItem = Enum.GetName(typeof(FilePropertiesTask.FileMissingActionType), fileMissingAction).Replace('_', ' ');
                #endregion

                #region FileWaitSeconds --> nudFileWaitSeconds
                DtsProperty propertyFileWaitSeconds = this._taskHost.Properties["FileWaitSeconds"];
                if (propertyFileWaitSeconds != null)
                {
                    this.chkFileWaitSeconds.Checked = (int)propertyFileWaitSeconds.GetValue(this._taskHost) > 0;
                    this.nudFileWaitSeconds.Value = (int)propertyFileWaitSeconds.GetValue(this._taskHost);
                }
                this.nudFileWaitSeconds.Enabled = this.chkFileWaitSeconds.Checked;
                #endregion

                #region FileExistenceVariableName --> cboFileExistenceVariableName
                this.cboFileExistenceVariableName.Items.Clear();
                foreach (Variable variable in this._taskHost.Variables)
                {
                    if ((variable.DataType == TypeCode.Boolean) && (!variable.SystemVariable))
                    {
                        this.cboFileExistenceVariableName.Items.Add(variable.QualifiedName);
                    }
                }

                string fileExistence = "";
                DtsProperty propertyFileExistence = this._taskHost.Properties["FileExistenceVariableName"];
                if (propertyFileExistence != null)
                {
                    fileExistence = (string)propertyFileExistence.GetValue(this._taskHost);
                }

                this.cboFileExistenceVariableName.SelectedItem = fileExistence;
                #endregion

                #region ParsedFileDirectoryVariableName --> cboParsedFileDirectoryVariableName
                this.cboParsedFileDirectoryVariable.Items.Clear();
                foreach (Variable variable in this._taskHost.Variables)
                {
                    if ((variable.DataType == TypeCode.String) && (!variable.SystemVariable))
                    {
                        this.cboParsedFileDirectoryVariable.Items.Add(variable.QualifiedName);
                    }
                }

                string parsedFileDirectory = "";
                DtsProperty propertyParsedFileDirectory = this._taskHost.Properties["ParsedFileDirectoryVariableName"];
                if (propertyParsedFileDirectory != null)
                {
                    parsedFileDirectory = (string)propertyParsedFileDirectory.GetValue(this._taskHost);
                }
                this.chkParsedFileDirectoryVariable.Checked = (parsedFileDirectory != "");
                this.cboParsedFileDirectoryVariable.SelectedItem = parsedFileDirectory;
                this.cboParsedFileDirectoryVariable.Enabled = (parsedFileDirectory != "");
                #endregion

                #region ParsedFileNameVariableName --> cboParsedFileNameVariableName
                this.cboParsedFileNameVariable.Items.Clear();
                foreach (Variable variable in this._taskHost.Variables)
                {
                    if ((variable.DataType == TypeCode.String) && (!variable.SystemVariable))
                    {
                        this.cboParsedFileNameVariable.Items.Add(variable.QualifiedName);
                    }
                }

                string parsedFileName = "";
                DtsProperty propertyParsedFileName = this._taskHost.Properties["ParsedFileNameVariableName"];
                if (propertyParsedFileName != null)
                {
                    parsedFileName = (string)propertyParsedFileName.GetValue(this._taskHost);
                }
                this.chkParsedFileNameVariable.Checked = (parsedFileName != "");
                this.cboParsedFileNameVariable.SelectedItem = parsedFileName;
                this.cboParsedFileNameVariable.Enabled = (parsedFileName != "");
                #endregion

                #region ConstructedFullFilePathVariableName --> cboConstructedFullFilePathVariableName
                this.cboConstructedFullFilePathVariable.Items.Clear();
                foreach (Variable variable in this._taskHost.Variables)
                {
                    if ((variable.DataType == TypeCode.String) && (!variable.SystemVariable))
                    {
                        this.cboConstructedFullFilePathVariable.Items.Add(variable.QualifiedName);
                    }
                }

                string constructedFullFilePath = "";
                DtsProperty propertyConstructedFullFilePath = this._taskHost.Properties["ConstructedFullFilePathVariableName"];
                if (propertyParsedFileName != null)
                {
                    constructedFullFilePath = (string)propertyParsedFileName.GetValue(this._taskHost);
                }
                this.chkConstructedFullFilePathVariable.Checked = (constructedFullFilePath != "");
                this.cboConstructedFullFilePathVariable.SelectedItem = constructedFullFilePath;
                this.cboConstructedFullFilePathVariable.Enabled = (constructedFullFilePath != "");
                #endregion

                #region FileReadableVariableName --> chkFileReadableVariable and cboFileReadableVariable
                this.cboFileReadableVariable.Items.Clear();
                foreach (Variable variable in this._taskHost.Variables)
                {
                    if ((variable.DataType == TypeCode.Boolean) && (!variable.SystemVariable))
                    {
                        this.cboFileReadableVariable.Items.Add(variable.QualifiedName);
                    }
                }

                string fileReadable = "";
                DtsProperty propertyFileReadable = this._taskHost.Properties["FileReadableVariableName"];
                if (propertyFileReadable != null)
                {
                    fileReadable = (string)propertyFileReadable.GetValue(this._taskHost);
                }

                this.chkFileReadableVariable.Checked = (fileReadable != "");
                this.cboFileReadableVariable.SelectedItem = fileReadable;
                this.cboFileReadableVariable.Enabled = (fileReadable != "");
                #endregion

                #region FileWriteableVariableName --> chkFileWriteableVariable and cboFileWriteableVariable
                this.cboFileWriteableVariable.Items.Clear();
                foreach (Variable variable in this._taskHost.Variables)
                {
                    if ((variable.DataType == TypeCode.Boolean) && (!variable.SystemVariable))
                    {
                        this.cboFileWriteableVariable.Items.Add(variable.QualifiedName);
                    }
                }

                string fileWriteable = "";
                DtsProperty propertyFileWriteable = this._taskHost.Properties["FileWriteableVariableName"];
                if (propertyFileWriteable != null)
                {
                    fileWriteable = (string)propertyFileWriteable.GetValue(this._taskHost);
                }

                this.chkFileWriteableVariable.Checked = (fileWriteable != "");
                this.cboFileWriteableVariable.SelectedItem = fileWriteable;
                this.cboFileWriteableVariable.Enabled = (fileWriteable != "");
                #endregion

                #region FileLengthVariableName --> chkFileLengthVariable and cboFileLengthVariable
                this.cboFileLengthVariable.Items.Clear();
                foreach (Variable variable in this._taskHost.Variables)
                {
                    if (((variable.DataType == TypeCode.Int64) || (variable.DataType == TypeCode.UInt64))
                        && (!variable.SystemVariable))
                    {
                        this.cboFileLengthVariable.Items.Add(variable.QualifiedName);
                    }
                }

                string fileLength = "";
                DtsProperty propertyFileLength = this._taskHost.Properties["FileLengthVariableName"];
                if (propertyFileLength != null)
                {
                    fileLength = (string)propertyFileLength.GetValue(this._taskHost);
                }

                this.chkFileLengthVariable.Checked = (fileLength != "");
                this.cboFileLengthVariable.SelectedItem = fileLength;
                this.cboFileLengthVariable.Enabled = (fileLength != "");
                #endregion

                #region Date Properties
                this.LoadPropertyControl(TypeCode.DateTime, "CreationDateAction", cboCreationDateAction, "CreationDateVariableName", cboCreationDateVariableName);
                this.LoadPropertyControl(TypeCode.DateTime, "AccessDateAction", cboAccessDateAction, "AccessDateVariableName", cboAccessDateVariableName);
                this.LoadPropertyControl(TypeCode.DateTime, "ModifiedDateAction", cboModifiedDateAction, "ModifiedDateVariableName", cboModifiedDateVariableName);
                #endregion

                #region Attributes
                this.LoadPropertyControl(TypeCode.Boolean, "AttributeArchiveAction", cboArchiveAttributeAction, "AttributeArchiveVariableName", cboArchiveAttributeVariableName);
                this.LoadPropertyControl(TypeCode.Boolean, "AttributeCompressedAction", cboCompressedAttributeAction, "AttributeCompressedVariableName", cboCompressedAttributeVariableName);
                this.LoadPropertyControl(TypeCode.Boolean, "AttributeEncryptedAction", cboEncryptedAttributeAction, "AttributeEncryptedVariableName", cboEncryptedAttributeVariableName);
                this.LoadPropertyControl(TypeCode.Boolean, "AttributeHiddenAction", cboHiddenAttributeAction, "AttributeHiddenVariableName", cboHiddenAttributeVariableName);
                this.LoadPropertyControl(TypeCode.Boolean, "AttributeReadOnlyAction", cboReadOnlyAttributeAction, "AttributeReadOnlyVariableName", cboReadOnlyAttributeVariableName);
                this.LoadPropertyControl(TypeCode.Boolean, "AttributeSystemAction", cboSystemAttributeAction, "AttributeSystemVariableName", cboSystemAttributeVariableName);
                this.LoadPropertyControl(TypeCode.Boolean, "AttributeTemporaryAction", cboTemporaryAttributeAction, "AttributeTemporaryVariableName", cboTemporaryAttributeVariableName);
                #endregion
            }
            #region catch ...
            catch
            {
                if (System.Diagnostics.Debugger.IsAttached)
                {
                    System.Diagnostics.Debugger.Break();
                }
            }
            #endregion
        }

        #region LoadPropertyControl
        private void LoadPropertyControl(TypeCode type, string actionPropertyName, ComboBox cboAction, string variablePropertyName, ComboBox cboVariableName)
        {
            cboAction.Items.Clear();
            foreach (string propertyActionType in Enum.GetNames(typeof(FilePropertiesTask.PropertyActionType)))
            {
                cboAction.Items.Add(propertyActionType.Replace('_', ' '));
            }
            cboVariableName.Items.Clear();
            if (type == TypeCode.Boolean)
            {
                cboVariableName.Items.Add(FilePropertiesTask.VARIABLE_ALWAYSTRUE);
                cboVariableName.Items.Add(FilePropertiesTask.VARIABLE_ALWAYSFALSE);
            }
            foreach (Variable variable in this._taskHost.Variables)
            {
                if (variable.DataType == type)
                {
                    cboVariableName.Items.Add(variable.QualifiedName);
                }
            }

            FilePropertiesTask.PropertyActionType action = FilePropertiesTask.PropertyActionType.Ignore;
            DtsProperty propertyAction = this._taskHost.Properties[actionPropertyName];
            if (propertyAction != null)
            {
                action = (FilePropertiesTask.PropertyActionType)propertyAction.GetValue(this._taskHost);
            }
            string variableName = "";
            DtsProperty propertyVariableName = this._taskHost.Properties[variablePropertyName];
            if (propertyVariableName != null)
            {
                variableName = (string)propertyVariableName.GetValue(this._taskHost);
            }

            cboAction.SelectedItem = Enum.GetName(typeof(FilePropertiesTask.PropertyActionType), action).Replace('_', ' ');
            cboVariableName.SelectedItem = variableName;
        }
        #endregion
        #endregion

        #region Control Event Handlers
        #region btnOK_Click
        private void btnOK_Click(object sender, EventArgs e)
        {
            try
            {
                #region cboFilePathNameSource --> FilePathNameSource
                FilePropertiesTask.PropertySourceType fileNameSource = (FilePropertiesTask.PropertySourceType)Enum.Parse(typeof(FilePropertiesTask.PropertySourceType), ((string)this.cboFilePathNameSource.SelectedItem).Replace(' ', '_'));
                DtsProperty fileNameSourceProperty = this._taskHost.Properties["FilePathNameSource"];
                if (fileNameSourceProperty != null)
                {
                    fileNameSourceProperty.SetValue(this._taskHost, fileNameSource);
                }
                #endregion

                #region cboFilePathNameVariable and txtFilePathNameStatic --> FilePathName
                string fileName = "";
                if (fileNameSource == FilePropertiesTask.PropertySourceType.Variable)
                {
                    fileName = (string)this.cboFilePathNameVariable.SelectedItem;
                }
                else
                {
                    fileName = this.txtFilePathNameStatic.Text;
                }

                DtsProperty filePathNameProperty = this._taskHost.Properties["FilePathName"];
                if (filePathNameProperty != null)
                {
                    filePathNameProperty.SetValue(this._taskHost, fileName);
                }
                #endregion

                #region cboFileMissingAction --> FileMissingAction
                FilePropertiesTask.FileMissingActionType fileMissingAction = (FilePropertiesTask.FileMissingActionType)Enum.Parse(typeof(FilePropertiesTask.FileMissingActionType), ((string)this.cboFileMissingAction.SelectedItem).Replace(' ', '_'));

                DtsProperty fileMissingActionProperty = this._taskHost.Properties["FileMissingAction"];
                if (fileMissingActionProperty != null)
                {
                    fileMissingActionProperty.SetValue(this._taskHost, fileMissingAction);
                }
                #endregion

                #region nudFileWaitSeconds --> FileWaitSeconds
                DtsProperty fileWaitSecondsProperty = this._taskHost.Properties["FileWaitSeconds"];
                if (fileWaitSecondsProperty != null)
                {
                    if (this.chkFileWaitSeconds.Checked)
                    {
                        fileWaitSecondsProperty.SetValue(this._taskHost, (int)this.nudFileWaitSeconds.Value);
                    }
                    else
                    {
                        fileWaitSecondsProperty.SetValue(this._taskHost, 0);
                    }
                }
                #endregion

                #region cboFileExistenceVariableName --> FileExistenceVariableName
                string fileExistence = (string)this.cboFileExistenceVariableName.SelectedItem;
                if (fileExistence == null)
                {
                    fileExistence = "";
                }
                DtsProperty fileExistenceVariableNameProperty = this._taskHost.Properties["FileExistenceVariableName"];
                if (fileExistenceVariableNameProperty != null)
                {
                    fileExistenceVariableNameProperty.SetValue(this._taskHost, fileExistence);
                }
                #endregion

                #region chkParsedFileDirectoryVariable and cboParsedFileDirectoryVariable --> ParsedFileDirectoryVariableName
                string parsedFileDirectory = "";
                if (this.chkParsedFileDirectoryVariable.Checked)
                {
                    parsedFileDirectory = (string)this.cboParsedFileDirectoryVariable.SelectedItem;
                }
                if (parsedFileDirectory == null)
                {
                    parsedFileDirectory = "";
                }
                DtsProperty parsedFileDirectoryVariableName = this._taskHost.Properties["ParsedFileDirectoryVariableName"];
                if (parsedFileDirectoryVariableName != null)
                {
                    parsedFileDirectoryVariableName.SetValue(this._taskHost, parsedFileDirectory);
                }
                #endregion

                #region chkParsedFileNameVariable and cboParsedFileNameVariable --> ParsedFileNameVariableName
                string parsedFileName = "";
                if (this.chkParsedFileNameVariable.Checked)
                {
                    parsedFileName = (string)this.cboParsedFileNameVariable.SelectedItem;
                }
                if (parsedFileDirectory == null)
                {
                    parsedFileDirectory = "";
                }
                DtsProperty parsedFileNameVariableNameProperty = this._taskHost.Properties["ParsedFileNameVariableName"];
                if (parsedFileNameVariableNameProperty != null)
                {
                    parsedFileNameVariableNameProperty.SetValue(this._taskHost, parsedFileName);
                }
                #endregion

                #region chkConstructedFullFilePathVariable and cboConstructedFullFilePathVariable --> ConstructedFullFilePathVariableName
                string constructedFullFilePath = "";
                if (this.chkConstructedFullFilePathVariable.Checked)
                {
                    constructedFullFilePath = (string)this.cboConstructedFullFilePathVariable.SelectedItem;
                }
                if (constructedFullFilePath == null)
                {
                    constructedFullFilePath = "";
                }
                DtsProperty constructedFullFilePathVariableNameProperty = this._taskHost.Properties["ConstructedFullFilePathVariableName"];
                if (constructedFullFilePathVariableNameProperty != null)
                {
                    constructedFullFilePathVariableNameProperty.SetValue(this._taskHost, constructedFullFilePath);
                }
                #endregion

                #region chkFileReadableVariable and cboFileReadableVariable --> FileReadableVariableName
                string fileReadable = "";
                if (this.chkFileReadableVariable.Checked)
                {
                    fileReadable = (string)this.cboFileReadableVariable.SelectedItem;
                }
                if (fileReadable == null)
                {
                    fileReadable = "";
                }
                DtsProperty fileReadableVariableNameProperty = this._taskHost.Properties["FileReadableVariableName"];
                if (fileReadableVariableNameProperty != null)
                {
                    fileReadableVariableNameProperty.SetValue(this._taskHost, fileReadable);
                }
                #endregion

                #region chkFileWriteableVariable and cboFileWriteableVariable --> FileWriteableVariableName
                string fileWriteable = "";
                if (this.chkFileWriteableVariable.Checked)
                {
                    fileWriteable = (string)this.cboFileWriteableVariable.SelectedItem;
                }
                if (fileWriteable == null)
                {
                    fileWriteable = "";
                }
                DtsProperty fileWriteableVariableNameProperty = this._taskHost.Properties["FileWriteableVariableName"];
                if (fileWriteableVariableNameProperty != null)
                {
                    fileWriteableVariableNameProperty.SetValue(this._taskHost, fileWriteable);
                }
                #endregion

                #region chkFileLengthVariable and cboFileLengthVariable --> FileLengthVariableName
                string fileLength = "";
                if (this.chkFileLengthVariable.Checked)
                {
                    fileLength = (string)this.cboFileLengthVariable.SelectedItem;
                }
                if (fileLength == null)
                {
                    fileLength = "";
                }
                DtsProperty fileLengthVariableNameProperty = this._taskHost.Properties["FileLengthVariableName"];
                if (fileLengthVariableNameProperty != null)
                {
                    fileLengthVariableNameProperty.SetValue(this._taskHost, fileLength);
                }
                #endregion

                this.SavePropertyControl(cboCreationDateAction, "CreationDateAction", cboCreationDateVariableName, "CreationDateVariableName");
                this.SavePropertyControl(cboAccessDateAction, "AccessDateAction", cboAccessDateVariableName, "AccessDateVariableName");
                this.SavePropertyControl(cboModifiedDateAction, "ModifiedDateAction", cboModifiedDateVariableName, "ModifiedDateVariableName");

                this.SavePropertyControl(cboArchiveAttributeAction, "AttributeArchiveAction", cboArchiveAttributeVariableName, "AttributeArchiveVariableName");
                this.SavePropertyControl(cboCompressedAttributeAction, "AttributeCompressedAction", cboCompressedAttributeVariableName, "AttributeCompressedVariableName");
                this.SavePropertyControl(cboEncryptedAttributeAction, "AttributeEncryptedAction", cboEncryptedAttributeVariableName, "AttributeEncryptedVariableName");
                this.SavePropertyControl(cboHiddenAttributeAction, "AttributeHiddenAction", cboHiddenAttributeVariableName, "AttributeHiddenVariableName");
                this.SavePropertyControl(cboReadOnlyAttributeAction, "AttributeReadOnlyAction", cboReadOnlyAttributeVariableName, "AttributeReadOnlyVariableName");
                this.SavePropertyControl(cboSystemAttributeAction, "AttributeSystemAction", cboSystemAttributeVariableName, "AttributeSystemVariableName");
                this.SavePropertyControl(cboTemporaryAttributeAction, "AttributeTemporaryAction", cboTemporaryAttributeVariableName, "AttributeTemporaryVariableName");

                this.DialogResult = DialogResult.OK;
                this.Close();
            }
            #region catch ...
            catch
            {
                if (System.Diagnostics.Debugger.IsAttached)
                {
                    System.Diagnostics.Debugger.Break();
                }
            }
            #endregion
        }

        #region SavePropertyControl
        private void SavePropertyControl(ComboBox cboAction, string actionPropertyName, ComboBox cboVariableName, string variablePropertyName)
        {
            FilePropertiesTask.PropertyActionType action = (FilePropertiesTask.PropertyActionType)Enum.Parse(typeof(FilePropertiesTask.PropertyActionType), ((string)cboAction.SelectedItem).Replace(' ', '_'));
            string variableName = (string)cboVariableName.SelectedItem;
            if (variableName == null)
            {
                variableName = "";
            }

            DtsProperty actionProperty = this._taskHost.Properties[actionPropertyName];
            if (actionProperty != null)
            {
                actionProperty.SetValue(this._taskHost, action);
            }
            DtsProperty variableProperty = this._taskHost.Properties[variablePropertyName];
            if (variableProperty != null)
            {
                variableProperty.SetValue(this._taskHost, variableName);
            }
        }
        #endregion
        #endregion

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void cboFilePathNameSource_SelectedIndexChanged(object sender, EventArgs e)
        {
            FilePropertiesTask.PropertySourceType fileNameSource = (FilePropertiesTask.PropertySourceType)Enum.Parse(typeof(FilePropertiesTask.PropertySourceType), ((string)this.cboFilePathNameSource.SelectedItem).Replace(' ', '_'));

            this.cboFilePathNameVariable.Visible = (fileNameSource == FilePropertiesTask.PropertySourceType.Variable);
            this.txtFilePathNameStatic.Visible = (fileNameSource == FilePropertiesTask.PropertySourceType.Static_Value);
            this.cmdFilePathNameBrowse.Visible = (fileNameSource == FilePropertiesTask.PropertySourceType.Static_Value);

            if (fileNameSource == FilePropertiesTask.PropertySourceType.Variable)
            {
                this.lblFileName.Text = "Variable";
            }
            else
            {
                this.lblFileName.Text = "File name";
            }
        }

        private void cboFileMissingAction_SelectedIndexChanged(object sender, EventArgs e)
        {
            FilePropertiesTask.FileMissingActionType fileMissingAction = (FilePropertiesTask.FileMissingActionType)Enum.Parse(typeof(FilePropertiesTask.FileMissingActionType), ((string)this.cboFileMissingAction.SelectedItem).Replace(' ', '_'));

            this.lblFileExistenceVariable.Visible = (fileMissingAction == FilePropertiesTask.FileMissingActionType.Task_Always_Succeeds_and_Records_File_Existence_In_Variable);
            this.cboFileExistenceVariableName.Visible = (fileMissingAction == FilePropertiesTask.FileMissingActionType.Task_Always_Succeeds_and_Records_File_Existence_In_Variable);
        }

        private void chkFileWaitSeconds_CheckedChanged(object sender, EventArgs e)
        {
            this.nudFileWaitSeconds.Enabled = this.chkFileWaitSeconds.Checked;
        }

        private void chkParsedFileDirectoryVariable_CheckedChanged(object sender, EventArgs e)
        {
            this.cboParsedFileDirectoryVariable.Enabled = this.chkParsedFileDirectoryVariable.Checked;
        }

        private void chkParsedFileNameVariable_CheckedChanged(object sender, EventArgs e)
        {
            this.cboParsedFileNameVariable.Enabled = this.chkParsedFileNameVariable.Checked;
        }

        private void chkConstructedFullFilePathVariable_CheckedChanged(object sender, EventArgs e)
        {
            this.cboConstructedFullFilePathVariable.Enabled = this.chkConstructedFullFilePathVariable.Checked;
        }

        private void chkFileReadableVariable_CheckedChanged(object sender, EventArgs e)
        {
            this.cboFileReadableVariable.Enabled = this.chkFileReadableVariable.Checked;
        }

        private void chkFileWriteableVariable_CheckedChanged(object sender, EventArgs e)
        {
            this.cboFileWriteableVariable.Enabled = this.chkFileWriteableVariable.Checked;
        }

        private void chkFileLengthVariable_CheckedChanged(object sender, EventArgs e)
        {
            this.cboFileLengthVariable.Enabled = this.chkFileLengthVariable.Checked;
        }

        private void cboAction_SelectedIndexChanged(object sender, EventArgs e)
        {
            ComboBox cboAction = (ComboBox)sender;
            Label lblAction2 = null;
            ComboBox cboVariableName = null;
            if (cboAction == this.cboCreationDateAction)
            {
                lblAction2 = this.lblCreationDateAction2;
                cboVariableName = this.cboCreationDateVariableName;
            }
            else if (cboAction == this.cboAccessDateAction)
            {
                lblAction2 = this.lblAccessDateAction2;
                cboVariableName = this.cboAccessDateVariableName;
            }
            else if (cboAction == this.cboModifiedDateAction)
            {
                lblAction2 = this.lblModifiedDateAction2;
                cboVariableName = this.cboModifiedDateVariableName;
            }
            else if (cboAction == this.cboArchiveAttributeAction)
            {
                lblAction2 = this.lblArchiveAttributeAction2;
                cboVariableName = this.cboArchiveAttributeVariableName;
            }
            else if (cboAction == this.cboCompressedAttributeAction)
            {
                lblAction2 = this.lblCompressedAttributeAction2;
                cboVariableName = this.cboCompressedAttributeVariableName;
            }
            else if (cboAction == this.cboEncryptedAttributeAction)
            {
                lblAction2 = this.lblEncryptedAttributeAction2;
                cboVariableName = this.cboEncryptedAttributeVariableName;
            }
            else if (cboAction == this.cboHiddenAttributeAction)
            {
                lblAction2 = this.lblHiddenAttributeAction2;
                cboVariableName = this.cboHiddenAttributeVariableName;
            }
            else if (cboAction == this.cboReadOnlyAttributeAction)
            {
                lblAction2 = this.lblReadOnlyAttributeAction2;
                cboVariableName = this.cboReadOnlyAttributeVariableName;
            }
            else if (cboAction == this.cboSystemAttributeAction)
            {
                lblAction2 = this.lblSystemAttributeAction2;
                cboVariableName = this.cboSystemAttributeVariableName;
            }
            else if (cboAction == this.cboTemporaryAttributeAction)
            {
                lblAction2 = this.lblTemporaryAttributeAction2;
                cboVariableName = this.cboTemporaryAttributeVariableName;
            }

            FilePropertiesTask.PropertyActionType propertyActionType = (FilePropertiesTask.PropertyActionType)Enum.Parse(typeof(FilePropertiesTask.PropertyActionType), ((string)cboAction.SelectedItem).Replace(' ', '_'));

            if (propertyActionType == FilePropertiesTask.PropertyActionType.Read)
            {
                lblAction2.Text = "into";
            }
            else if (propertyActionType == FilePropertiesTask.PropertyActionType.Write)
            {
                lblAction2.Text = "from";
            }
            else if (propertyActionType == FilePropertiesTask.PropertyActionType.Write_Then_Read)
            {
                lblAction2.Text = "from/into";
            }
            lblAction2.Visible = (propertyActionType != FilePropertiesTask.PropertyActionType.Ignore);
            cboVariableName.Visible = (propertyActionType != FilePropertiesTask.PropertyActionType.Ignore);
        }

        private void cmdFilePathNameBrowse_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();

            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                this.txtFilePathNameStatic.Text = openFileDialog.FileName;
            }
        }
        #endregion
    }
}
